package net.hn.hnms.biz.plan.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.hn.hnms.biz.plan.request.ExecutionFootageOutputReq;
import net.hn.hnms.biz.plan.service.impl.ExecutionFootageOutputServiceImpl;
import net.hn.hnms.biz.plan.vo.ExecutionFootageOutputVO;
import net.hn.hnms.biz.plan.vo.MiningFaceScheduleVo;
import net.hn.hnms.biz.plan.vo.MiningstasticVo;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.excel.utils.ExcelUtil;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 进尺产量执行
 *
 * @author zhaoyang
 * @date 2022-08-01
 */
@Slf4j
@Api(value = "进尺产量执行模块", tags = {"进尺产量执行"})
@RestController
@RequestMapping("/execution/output")
public class ExecutionFootageOutputController extends BaseController {


    @Autowired
    private ExecutionFootageOutputServiceImpl executionFootageOutputService;


    /**
     * 新增进尺产量执行
     */
    @ApiOperation("新增进尺产量执行")
    @SaCheckPermission("execution:footage:output:add")
    @PostMapping("/add")
    @Log(title = "新增进尺产量执行", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody ExecutionFootageOutputReq executionFootageOutput) {
        return toAjax(executionFootageOutputService.insert(executionFootageOutput));
    }

    /**
     * 删除进尺产量执行
     */
    @ApiOperation("删除进尺产量执行")
    @SaCheckPermission("execution:footage:output:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("delete")
    @Log(title = "删除进尺产量执行", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        executionFootageOutputService.deleteBatch(idList);
        return R.ok();
    }

    /**
     * 修改进尺产量执行
     */
    @ApiOperation("修改进尺产量执行")
    @SaCheckPermission("execution:footage:output:update")
    @PutMapping("/update")
    @Log(title = "修改进尺产量执行", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody ExecutionFootageOutputReq executionFootageOutput) {
        executionFootageOutputService.updateById(executionFootageOutput);
        return R.ok();
    }

    /**
     * 获取进尺产量执行列表
     */
    @ApiOperation("获取进尺产量执行分页列表")
//    @SaCheckPermission("execution:footage:output:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<ExecutionFootageOutputVO>> page(ExecutionFootageOutputReq executionFootageOutput, PageQuery pageQuery) {
        return R.ok(executionFootageOutputService.selectPageList(executionFootageOutput, pageQuery));
    }

    /**
     * 获取进尺产量执行列表
     */
    @ApiOperation("获取进尺产量执行列表")
//    @SaCheckPermission("execution:footage:output:list")
    @GetMapping("/list")
    @AutoSetMineCode
    public R<List<ExecutionFootageOutputVO>> list(ExecutionFootageOutputReq executionFootageOutput) {
        return R.ok(executionFootageOutputService.selectList(executionFootageOutput));
    }


    @ApiOperation("导出进尺产量执行列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExecutionFootageOutputReq executionFootageOutput) {
        List<ExecutionFootageOutputVO> executionFootageOutputVOS = executionFootageOutputService.selectListOfExport(executionFootageOutput);
        ExcelUtil.exportExcel(executionFootageOutputVOS, "进尺产量执行数据", ExecutionFootageOutputVO.class, response);
    }

    /**
     * 获取进尺产量执行详情
     */
    @ApiOperation("获取进尺产量执行详情")
//    @SaCheckPermission("execution:footage:output:list")
    @GetMapping("/{id}")
    public R<ExecutionFootageOutputVO> detail(@PathVariable("id") String id) {
        return R.ok(executionFootageOutputService.selectDetailById(id));
    }

    @ApiOperation("获取进尺(m)产量(t) 根据工作面ID")
    @GetMapping("/footageAndoutput/{workFaceId}")
    public R<ExecutionFootageOutputVO> detailFootageAndDevelop(@PathVariable("workFaceId") String id) {
        return R.ok(executionFootageOutputService.selectFootageAndDevelop(id));
    }


    @ApiOperation("根据日期获取进尺(m)产量(t) 根据工作面ID")
    @GetMapping("/footageAndoutput/detailFootageAndDevelopByData")
    public R<List<ExecutionFootageOutputVO>> detailFootageAndDevelopByData( String id,String date) {
        return R.ok(executionFootageOutputService.detailFootageAndDevelopByData(id,date));
    }
    @ApiOperation("获取近7日得 进尺(m)产量(t) 根据工作面ID")
    @GetMapping("/getLastSevenDaysDetailFD/{workFaceId}")
    public R<List<ExecutionFootageOutputVO>> getLastSevenDaysDetailFD(@PathVariable("workFaceId") String id) {
        return R.ok(executionFootageOutputService.selectLastSevenDaysDetailFD(id));
    }


    @ApiOperation("获取回采工作面进度")
    @GetMapping("/getMiningFaceSchedule")
    public R<MiningFaceScheduleVo> getMiningFaceSchedule(String name) {
        return R.ok(executionFootageOutputService.getMiningFaceSchedule(name));
    }



    @ApiOperation("查询生产信息统计数据掘进面")
//    @SaCheckPermission("dispatch:keepwatch:exportDuty")
    @GetMapping("/getProductionStatisticsDrivage")
    @Log(title = "查询生产信息统计数据", businessType = BusinessType.EXPORT)
    @AutoSetMineCode
    public R<List<ExecutionFootageOutputVO>> getProductionStatisticsDrivage( String beginDate,String mineCode){
        return R.ok(executionFootageOutputService.getProductionStatisticsDrivage(beginDate,mineCode));
    }

    @ApiOperation("查询生产信息统计数据回采面")
//    @SaCheckPermission("dispatch:keepwatch:exportDuty")
    @GetMapping("/getProductionStatisticsMining")
    @Log(title = "查询生产信息统计数据", businessType = BusinessType.EXPORT)
    @AutoSetMineCode
    public  R<List<ExecutionFootageOutputVO>> getProductionStatisticsMining( String beginDate,String mineCode){
        return R.ok(executionFootageOutputService.getProductionStatisticsMining(beginDate,mineCode));
    }


//    @ApiOperation("导出生产信息统计数据")
//    @SaCheckPermission("dispatch:keepwatch:exportDuty")
//    @PostMapping("/exportProductionStatistics")
//    @Log(title = "导出生产信息统计数据", businessType = BusinessType.EXPORT)
//    @AutoSetMineCode
//    public void exportProductionStatistics(HttpServletResponse response, String beginDate,String mineCode){
//        log.info("exportProductionStatistics");
//        executionFootageOutputService.exportProductionStatisticsData(response,beginDate,mineCode);
//    }


    @ApiOperation("获取生产信息统计数据列表")
//    @SaCheckPermission("execution:footage:output:list")
    @GetMapping("/MiningFaceProductionStatisticsList")
    @AutoSetMineCode
    public R<List<MiningstasticVo>> productionStatisticsList(String beginDate, String mineCode) {
        log.info("MiningFaceProductionStatisticsList");
        return R.ok(executionFootageOutputService.productionStatisticsList(beginDate,mineCode));
    }

}
